

using System.Linq;
using Abp.Authorization;
using Abp.Configuration.Startup;
using Abp.Localization;
using Abp.MultiTenancy;
using JYJ.AiYard.Authorization;

namespace JYJ.AiYard.StationManagement.TbYardPayMonthCards.Authorization
{
    /// <summary>
    /// 权限配置都在这里。
    /// 给权限默认设置服务
    /// See <see cref="TbYardPayMonthCardPermissions" /> for all permission names. TbYardPayMonthCard
    ///</summary>
    public class TbYardPayMonthCardAuthorizationProvider : AuthorizationProvider
    {
        private readonly bool _isMultiTenancyEnabled;

		public TbYardPayMonthCardAuthorizationProvider()
		{

		}

        public TbYardPayMonthCardAuthorizationProvider(bool isMultiTenancyEnabled) 
        {
            _isMultiTenancyEnabled = isMultiTenancyEnabled;
        }

        public TbYardPayMonthCardAuthorizationProvider(IMultiTenancyConfig multiTenancyConfig)
        {
            _isMultiTenancyEnabled = multiTenancyConfig.IsEnabled;
        }

		public override void SetPermissions(IPermissionDefinitionContext context)
		{
			// 在这里配置了TbYardPayMonthCard 的权限。
			var pages = context.GetPermissionOrNull(AppLtmPermissions.Pages) ?? context.CreatePermission(AppLtmPermissions.Pages, L("Pages"));


			var payparams = pages.Children.FirstOrDefault(p => p.Name == AppPermissions.Pages_YardManage) ??
							pages.CreateChildPermission(AppPermissions.Pages_YardManage, L("Yard_Management"));

			var administration = payparams.Children.FirstOrDefault(p => p.Name == AppPermissions.Pages_YardManage_ChargingStandard) ?? payparams.CreateChildPermission(AppPermissions.Pages_YardManage_ChargingStandard, L("Yard_ChargingStandard"));

			var entityPermission = administration.CreateChildPermission(TbYardPayMonthCardPermissions.Node, L("TbYardPayMonthCard"));
			entityPermission.CreateChildPermission(TbYardPayMonthCardPermissions.Query, L("QueryTbYardPayMonthCard"));
			entityPermission.CreateChildPermission(TbYardPayMonthCardPermissions.Create, L("CreateTbYardPayMonthCard"));
			entityPermission.CreateChildPermission(TbYardPayMonthCardPermissions.Edit, L("EditTbYardPayMonthCard"));
			entityPermission.CreateChildPermission(TbYardPayMonthCardPermissions.Delete, L("DeleteTbYardPayMonthCard"));
			entityPermission.CreateChildPermission(TbYardPayMonthCardPermissions.BatchDelete, L("BatchDeleteTbYardPayMonthCard"));

		}

		private static ILocalizableString L(string name)
		{
			return new LocalizableString(name, AppConsts.LocalizationSourceName);
		}
    }
}